	<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<title>预约规则列表</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
	<section class="content-header">
		<h1>预约规则列表</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active">药品招标管理</li>
            <li class="active">预约管理</li>
			<li class="active">预约</li>
			<li class="active">预约规则列表</li>
		</ol>
	</section>

	<section class="content">
		<div class=" box box-success">
			<div class="box-body">
				<div class=" form-inline">
					<div class="form-group form-group-xs">
						<label for="txtDrugName">预约日期：</label> 
						 <input style="width: 100px;" placeholder="开始日期" name="subStartDate" id="subStartDate" type="text"  value="" readonly="readonly" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" placeholder="yyyy-mm-dd">
                   	   <label>-</label>
                       <input  style="width: 100px;" placeholder="结束日期" name="subEndDate" id="subEndDate" type="text"  value=""readonly="readonly" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" placeholder="yyyy-mm-dd">
					</div>
					<div class="form-group form-group-xs">
						 <label for="txtDrugSpec">是否包含周末：</label>
						 <select class='form-control' id="includeWeekend" style="width: 150px;">
						 	<option value="">请选择</option>
						 	<option value="0">否</option>
						 	<option value="1">是</option>
						 </select>
					</div> 
						<button type="button" onclick="likeQuery();" class="btn btn-success btn-sm">查&nbsp;询</button>
				   </div>
			</div>
		</div>
		<table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		<div class=" box box-warning bottongroup">
			<%-- <a href="${ctx }/bidSubscribe/toCenterSubscribeJsp.html" class="btn btn-default btn-sm">新增预约</a> --%>
			<a href="javascript:start(1)" class="btn btn-default btn-sm">开启预约</a>
			<a href="javascript:start(0)" class="btn btn-default btn-sm">关闭预约</a>
			<a href="javascript:back();" class="btn btn-default btn-sm">返&nbsp;回</a>
		</div>
		<form action="${ctx }/bidSubscribe/toSubscribeEditJsp.html" method="post" id="FormSubmit">
			<input type="hidden" id="bidSubscribeId" name="bidSubscribeId">
		</form>
	</section>
   <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script src="${ctx}/lib/plugins/daterangepicker/moment.js"></script>
    <script src="${ctx}/lib/plugins/daterangepicker/daterangepicker.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#projId").HNSelect({
	            url: "${pageContext.request.contextPath}/selectController/getDicBidCompany.html", data: { ID: '' }, defaultText: "<option value=''>请选择</option>",
	        });
			$("#gridlist").jqGrid({
								url : "getBidSubscribeData.html",
								mtype : "POST",
								datatype : "json",
								postData : {"projId":"${projId}"},
								autowidth : true,
								shrinkToFit:false,
								height : 270,
								colNames : [ '预约id', '项目名称', '预约活动日期','是否包含周末','处理事务时间段一','时间段一单位','时间段一单位上限人数','时间段一已预约人数','时间段一预约上限人数', '处理事务时间段二','时间段二单位','时间段二单位上限人数', '时间段二已预约人数','时间段二预约上限人数','状态','备注','更新时间', '更新人' ],
								colModel : [
								            {name : 'bidSubscribeId',width : 100,align : "center",hidden : true,sortable : false},
											{name : 'projName',width : 200,align : "left",sortable : false},
										    {name : 'subDate',width : 160,align : "center",sortable : false,
												formatter : function(val, opts,
														rowdata) {
													return rowdata.subStartDateStr+" - "+rowdata.subEndDateStr;
												}
										    },
										    {name : 'includeWeekend',width : 80,align : "center",sortable : false,
										    	formatter : function(val, opts,
														rowdata) {
													var str = "";
													if (rowdata.includeWeekend == 1) {
														str = "是";
													}
													if (rowdata.includeWeekend == 0) {
														str = "否";
													}
													return str;
											}	
										    },
										    {name : 'processTimeOneStr',width : 120,align : "center",sortable : false,
												formatter : function(val, opts,
														rowdata) {
													return rowdata.processStartTimeOneStr+" - "+rowdata.processEndTimeOneStr;
												}
										    },
										    {name : 'processUnitOne',width : 90,align : "center",sortable : false,
										    	formatter : function(val, opts,
														rowdata) {
													return rowdata.processUnitOne+"分钟"
												}		
										    },
										    {name : 'personCountOne',width : 130,align : "center",sortable : false},
										    {name : 'personNumOne',width : 120,align : "center",sortable : false,
										    	formatter : function(val, opts,
														rowdata) {
													var str = "<a href=\"javascript:seachNum('"+rowdata.bidSubscribeId+"',1,'"+rowdata.projId+"');\">"+val+"</a>";
													return str;
											}	
										    },
										    {name : 'personCountOne',width : 130,align : "center",sortable : false},
										    {name : 'processStartTimeTwoStr',width : 120,align : "center",sortable : false,
												formatter : function(val, opts,
														rowdata) {
													return rowdata.processStartTimeTwoStr+" - "+rowdata.processEndTimeTwoStr;
												}
										    },
										    {name : 'processUnitTwo',width : 90,align : "center",sortable : false,
										    	formatter : function(val, opts,
														rowdata) {
													return rowdata.processUnitTwo+"分钟"
												}	
										    },
										    {name : 'personCountTwo',width : 130,align : "center",sortable : false},
										    {name : 'personNumTwo',width : 120,align : "center",sortable : false,
										    	formatter : function(val, opts,
														rowdata) {
													var str = "<a href=\"javascript:seachNum('"+rowdata.bidSubscribeId+"',2,'"+rowdata.projId+"');\">"+val+"</a>";
													return str;	
										    	}
										    },
										    {name : 'personCountTwo',width : 130,align : "center",sortable : false},
										    {name : 'status',width : 60,align : "center",sortable : false,
												formatter : function(val, opts,
														rowdata) {
													var str = "";
													if (rowdata.status == 1) {
														str = "开启中";
													}
													if (rowdata.status == 0) {
														str = "已关闭";
													}
													return str;
											}
										},
										{name : 'remarks',width : 80,align : "center",sortable : false},
										{name : 'updDatetimeStr',width : 140,align : "center",sortable : false},
										{name : 'updUser',width : 160,align : "center",sortable : false}
										],
								rowNum : 20,
								rowList : [ 10, 20, 50,100 ],
								rownumbers : true,
								pager : "#gridpage",
								multiselect : true,
								viewrecords : true,
								caption : "预约规则列表",
								jsonReader : {
									repeatitems : false,
									id : "ids"
								}
							});
			$("#gridlist").jqGrid('navGrid', '#gridpage', {
				add : false,
				edit : false,
				del : false,
				search : false,
				refresh : false
			});

			 $(window).trigger("resize");
		});
		
		function back(){
			window.location.href="${ctx}/bidSubscribe/toSetSubProjListJsp.html";
		}
		function start(obj){
					var checked = false;
					$("input.cbox").each(function() {
						if ($(this).is(":checked")) {
							checked = true;
							return false;
						}
						;
					});

					if (!checked) {
						$.HN.message.alert('必须选择才能进行操作', '提示信息',
								'failed');
					} else {

						var rowIds = $("#gridlist").jqGrid(
								'getGridParam', 'selarrrow');
						var bidSubscribeId = "";
						var number = 0;
						for (var i = 0; i < rowIds.length; i++) {
							
							var rowdata = $("#gridlist").jqGrid(
									'getRowData', rowIds[i]);
							
							if(1 == obj && rowdata.status=="开启中"){
								number += 1;
								continue;
							}
							if(0 == obj && rowdata.status=="已关闭"){
								number += 1;
								continue;
							}
							bidSubscribeId += rowdata.bidSubscribeId + ",";
						}
						number = rowIds.length - number;
						
						var msgStr = obj==1?'启用':'停用';
						$.HN.message
								.confirm('确定'+msgStr+number+'条吗？', '', '')
								.on(
										function(e) {
											if (e) {
												$.ajax({
															type : "POST",
															url : "${ctx}/bidSubscribe/toSubscribeStatusUpdate.html",
															data : "bidSubscribeId="
																	+ bidSubscribeId
																	+ "&status="+obj,
															dataType:"json",
															success : function(result) {
																if(result.success){
																	$.HN.message.alert('操作成功！','信息', 'success');
																	likeQuery();
																}else{
																	$.HN.message.alert('操作失败！','信息', 'error');
																}
															}
														});
											}
										});
					}
				}
		
		function edit(id) {
			$("#bidSubscribeId").val(id);
			$("#FormSubmit").submit();

		}

		function seachNum(id,number,projId){
			window.location.href="${ctx}/bidSubscribe/toSubscribeCompListJsp.html?bidSubscribeId="+id+"&number="+number+"&projId="+projId;
		}
		
		function likeQuery() {
			var projId = "${projId}";
			var subStartDate = $("#subStartDate").val();
			var subEndDate = $("#subEndDate").val();
			var includeWeekend = $("#includeWeekend").val();
		
			$("#gridlist").jqGrid('setGridParam',{
				       	    	datatype:'json',
				                postData:{
				                	"projId":projId,
				                	"subStartDate":subStartDate,
				                	"subEndDate":subEndDate,
				                	"includeWeekend":includeWeekend
				                	},
				                page : 1
			}).trigger("reloadGrid");
		}
		
      
	</script>
</body>
</html>









